package com.agm.android.fragments;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.agm.android.binder.BinderClassifica;
import com.agm.dto.Squadra;
import com.example.android.navigationdrawerexample.App;
import com.example.android.navigationdrawerexample.R;
//import android.content.Intent;

public class ClassificaFragment extends Fragment {
	public static final String ARG_PLANET_NUMBER = "planet_number";
//	private Intent intent ;
	public ClassificaFragment() {
		// Empty constructor required for fragment subclasses
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.fragment_classifica, container,false);
		if(App.squadre != null && App.lega != null){
	        ListView listView = (ListView) rootView.findViewById(R.id.listViewClassifica);
			
			List<HashMap<String, String>> contentDataCollection = new ArrayList<HashMap<String, String>>();
			HashMap<String, String> map = null;
			for(int i=0;i<App.squadre.length;i++){
	            Squadra row  = App.squadre[i];
	            
	            map = new HashMap<String, String>();
	            map.put(BinderClassifica.KEY_POSIZIONE,"" + (i + 1) );
	            map.put(BinderClassifica.KEY_NOME, row.getNomesquadra());
	            map.put(BinderClassifica.KEY_VINTE,"" + row.getVinte());
	            map.put(BinderClassifica.KEY_PUNTI,"" + row.getPunti());
	            map.put(BinderClassifica.KEY_MEDIA,"" + row.getFantamedia());
	            map.put(BinderClassifica.KEY_SUBITI,"" + row.getGolsubiti());
	            map.put(BinderClassifica.KEY_FATTI,"" + row.getGolfatti());
	            map.put(BinderClassifica.KEY_NULLE,"" + row.getNeutre());
	            map.put(BinderClassifica.KEY_PERSE,"" + row.getPerse());
	            contentDataCollection.add(map);
	
			}  
			BinderClassifica bindingData = new BinderClassifica(inflater, contentDataCollection);
			listView.setAdapter(bindingData);
		}
		return rootView;
	}
}
